package com.qf.controller;

import com.qf.annotation.NoLogin;
import com.qf.common.R;
import com.qf.param.LoginParam;
import com.qf.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author zdl
 * @date 2025/4/14
 */
@RestController
@RequestMapping("/user")
public class LoginController {
    @Resource
    private UserService userService;

    @NoLogin
    @PostMapping("/login")
    public R<String> login(@RequestBody LoginParam loginParam, HttpSession session){
        session.setAttribute("username",loginParam.getUsername());
        return R.ok(userService.loginUser(loginParam));
    }
    @NoLogin
    @PostMapping("/logout")
    public R<String> logout(HttpSession session){
       session.invalidate();
       return R.ok("logout success");
    }
}
